import { defineStore } from 'pinia'
import { ref } from 'vue'

export const tableDataStore = defineStore('car', () => {
  const activeIndex = ref(0)
  const tableData = ref([])
  const queryData = ref([])

  const items = ref([
    { id: 0, text: '排班' },
    { id: 1, text: '已发车' },
    { id: 2, text: '返程中' },
  ])

  //切换activeIndex
  const changeActiveIndex = item => {
    activeIndex.value = item
  }
  //重置queryData
  const resetQueryData = () => {
    queryData.value = []
  }
  //给tableData赋值
  const changeTableData = newValue => {
    tableData.value = newValue
  }
  const query = input => {
    if (!input.trim()) {
      queryData.value = []
      return
    }
    queryData.value = tableData.value.filter(item =>
      item.car_number.includes(input.trim())
    )
  }
  return {
    tableData,
    activeIndex,
    queryData,
    items,
    changeActiveIndex,
    resetQueryData,
    changeTableData,
    query,
  }
})
